/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package genetic;

import Utilities.Tradutor;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.neuroph.core.learning.DataSet;
import org.neuroph.util.TrainingSetImport;

/**
 *
 * @author Celso
 */
public class GenTest {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        // setup
        String dataSetFileName = "dataSet.txt";

        int inputsCount = 41;
        int outputsCount = 1;

        // create dataSets
        DataSet dataSet = null;
        DataSet trainingSet = null;
        DataSet testingSet = null;
        
        try {
            dataSet = TrainingSetImport.importFromFile(dataSetFileName, inputsCount, outputsCount, ",");
        } catch (FileNotFoundException ex) {
            System.out.println("TrainingSet file not found!");
        } catch (IOException | NumberFormatException ex) {
            System.out.println("Error reading file or bad number format!");
            System.out.println("Using COMA ',' separator?");
        }

        // normalize data
        dataSet.normalize();

        DataSet[] c = dataSet.createTrainingAndTestSubsets(20, 80);
        trainingSet = c[0];
        testingSet = c[1];

        // genetic algorithm setup
        Integer populationSize = 30;
        Integer candidateSinze = 28; // don't change
        Double crossoverRate = 0.75;
        Double mutationRate = 0.02;
        Integer generations = 5;
        Integer elitism = 3;

        GeneticAlgorithm genetic = new GeneticAlgorithm(
                candidateSinze,
                crossoverRate,
                mutationRate,
                trainingSet,
                testingSet);
        // It's only to observe the evolution over the time
        genetic.observeEvolution();
        
        // initialize the evolution process
        genetic.evolve(populationSize, elitism,generations);

        // to explain in human language the result
        Tradutor t = new Tradutor();
        t.translate(genetic.getResult());

        System.out.println("Function:" + t.getTransferFunctionType());
        System.out.println("hiddenNeurons:" + t.getHiddenNeurons());
        System.out.println("learnRate:" + t.getLearnRate());
        System.out.println("momentum:" + t.getMomentum());

    }

}
